﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Mooc
{
    public partial class TeaApp : Form
    {
        public TeaApp(Home home, Tea tea)
        {
            InitializeComponent();
            this.home = home;
            this.tea = tea;
            getWork();
        }

        Home home;

        Tea tea;

        SqlDao sqlDao = new SqlDao();

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                index = e.RowIndex;
                Work work = new Work();
                work.S_id = dataGridView1.Rows[e.RowIndex].Cells["学号"].Value.ToString();
                work.W_id = dataGridView1.Rows[e.RowIndex].Cells["作业ID"].Value.ToString();
                work.W_content = dataGridView1.Rows[e.RowIndex].Cells["作业内容"].Value.ToString();
                work.T_id = tea.T_id;
                UpdateWork updateWork = new UpdateWork(work,this);
                updateWork.ShowDialog();
            }
        }

        bool e1 = true;
        private void getWork()
        {
            DataSet ds = sqlDao.selectWorkByState(0);
            if (ds.Tables[0].Rows.Count > 0)
            {
                dataGridView1.DataSource = ds.Tables[0].DefaultView;
                if (e1)
                {
                    DataGridViewButtonColumn column = new DataGridViewButtonColumn();
                    column.Text = "批 改";
                    column.Name = "编 辑";
                    column.UseColumnTextForButtonValue = true;
                    dataGridView1.Columns.Add(column);
                    dataGridView1.Columns[3].Width = 400;
                    e1 = false;
                }
            }
        }

        int index;
        public void delete()
        {
            dataGridView1.Rows.RemoveAt(index);
        }

        private void tabControl1_Selected(object sender, TabControlEventArgs e)
        {
            if (e.TabPageIndex == 0)
            {
                getWork();
            }
            else if(e.TabPageIndex==1)
            {
                DataSet ds = sqlDao.selectOpinionById(tea.T_id);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    dataGridView2.DataSource = ds.Tables[0].DefaultView;
                }
            }
            else if (e.TabPageIndex == 2)
            {
                if (MessageBox.Show("确定要退出...", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    home.openForm(new Login(home));
            }
        }
    }
}
